﻿@page "/CreatRDK"
@inject CKDServer cKDServer
@using System.ComponentModel
@using AntDesign.TableModels
@using Microsoft.AspNetCore.Http
@inject ModalService _modalService
@inject MessageService _message
@inject IHttpContextAccessor httpContextAccessor
<style>
    input[type=checkbox] {
        cursor: pointer;
        width: 20px;
        height: 20px;
        font-size: 14px;
    }

        input[type=checkbox]::after {
            color: #000;
            width: 20px;
            height: 20px;
            display: inline-block;
            visibility: visible;
            padding-left: 0px;
            text-align: center;
            content: ' ';
            border-radius: 3px
        }

        input[type=checkbox]:checked::after {
            content: "✓";
            color: #fff;
            font-size: 12px;
            font-weight: bold;
            background-color: #00FF00;
        }
</style>
<h3>绑定仓位</h3>
<div>
    <Row>
        <Col Span="24">扫码输入框</Col>
    </Row>
    <Row>
        @* <Col Span="24">
        <Input style="width:100%" Placeholder="Basic usage" @bind-Value="@ss" @onkeydown="Change">
        </Col>*@
       @* <Input style="width:100%" Placeholder="Basic usage" @bind-Value="@ss" @onkeydown="Change" ></Input>*@
       <input @ref="input" Type="text" style="width:100%;" placeholder="Basic usage" @bind:event="oninput" @bind="@ss" @onkeydown="Change" />

    </Row>
    <Row>
        <Col Span="24">批号</Col>
    </Row>
    <Row>
        <Col Span="24">
        <Input style="width:100%" Placeholder="Basic usage" @bind-Value="@Batch" />
        </Col>
    </Row>

    @*<Row>
    <Col Span="24">区域（A区输入001,B区输入002）</Col>
    </Row>
    <Row>
    <Col Span="24">
    <Input style="width:100%" Placeholder="Basic usage" @bind-Value="@Area" />
    </Col>
    </Row>*@
    <br />
    <Row>

        <div class="box">
           @* <input type="checkbox" name="checkA" checked="@IsAArea" disabled="@IsAArea" @onchange=" IsCheckedA">
            <label style="margin-right:30px;font-size:20px;text-align: center">A区</label>
            <input type="checkbox" checked="@IsBArea" disabled="@IsBArea" @onchange="IsCheckedB">
            <label style="font-size:20px;text-align: center">B区</label>*@
            <input type="checkbox" checked="@IsCArea" disabled="@IsCArea" @onchange="IsCheckedB">
            <label style="font-size:20px;text-align: center">C区</label>
        </div>
    </Row>

    <br>
    <Row>
        <Col Span="24">仓位</Col>
    </Row>
    <Row>
        <Col Span="24">
        <Input style="width:100%" Placeholder="Basic usage" @bind-Value="@CW" />
        </Col>
    </Row>
    <Row>
        <Col Span="24">
        <Button style="width:100%" Type="@ButtonType.Primary">解析二维码</Button>@*@onclick="@Change"*@

        <br>
        <br>
        <Button style="width:100%" Type="@ButtonType.Primary" @onclick="@Creat">提交</Button>
        <br>
        </Col>
    </Row>
</div>

@code {
    string Batch { get; set; }
    string CW { get; set; }
    string Area { get; set; }
    string ss { get; set; }
    bool IsAArea { get; set; } = true;
    bool IsBArea { get; set; } = false;
    bool IsCArea { get; set; } = true;
    bool IsFocus { get; set; } = true;
    private ElementReference input;
    protected override async Task OnInitializedAsync()
    {
        base.OnInitialized();
        
       
    }
   
    private void Change(KeyboardEventArgs e)
    {
        
        try
        {
            if (e.Key == "Enter")
            {
                if (!string.IsNullOrEmpty(ss))
                {
                    var a = ss.Split(',');
                    Batch = a[0];
                    //for (int i = 0; i < a.Length; i++)
                    //{
                    //    if (a[i].Contains("Flot"))
                    //    {
                    //        Batch = a[i].Remove(0, 4);
                    //    }
                    //}
                }
            }
            
        }
        catch (Exception)
        {
            
           
        }



    }
    private void IsCheckedA()
    {


        IsAArea = true;
        IsBArea = false;
    }
    private void IsCheckedB()
    {
        IsAArea = false;
        IsBArea = true;
    }
    private async Task Creat()
    {

       await _modalService.ConfirmAsync(new ConfirmOptions()
            {
                Title = "提示",
                Icon =@<Icon Type="exclamation-circle" Theme="Outline"></Icon>,
                OkText = "确认",
            OnOk = async (e) =>
            {
                if (IsAArea == true)
                {
                    Area = "001";
                }
                if(IsBArea==true)
                {
                    Area = "002";
                }
                if(IsCArea==true)
                {
                   Area = "003";
                }
               var hc = httpContextAccessor.HttpContext;
               var employee = hc.User.FindFirst("employeeName").Value;
               var aa = await cKDServer.UpdataCW(Batch, CW, Area,employee);
               _message.Info(aa);
               
            },
            CancelText = "取消",
            Content = "是否提交？",
        });
        Batch = "";
        ss = "";
        input.FocusAsync();
    }
}
